package org.uned.agonzalo16.bitacora.web.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.uned.agonzalo16.bitacora.dao.ArticleDao;
import org.uned.agonzalo16.bitacora.domain.Blog;

@Configurable
@SuppressWarnings("serial")
public class ArticlesNumberByBlogTag extends TagSupport {

	private transient Blog blog;

	@Autowired
	private transient ArticleDao articleDao;

	public void setBlog(Blog blog) {
		this.blog = blog;
	}

	@Override
	public int doStartTag() throws JspException {

		try {
			pageContext.getOut().print(articleDao.countByBlog(blog));
		} catch (IOException ioe) {
			throw new JspTagException(ioe.toString(), ioe);
		}
		return SKIP_BODY;
	}
}
